﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MeetFuture.MRC
{
    public partial class FrmLoader : Form, INotifyPropertyChanged
    {
        private int _Percentage;
        private string _Detail;
        public int Percentage
        {
            get => _Percentage;
            set
            {
                if (_Percentage != value)
                {
                    _Percentage = value;

                    OnPropertyChanged("Percentage");
                }
            }
        }
        public string Detail
        {
            get => _Detail;
            set
            {
                if (_Detail != value)
                {
                    _Detail = value;

                    OnPropertyChanged("Detail");
                }
            }
        }
        public Action LoadHandler { get; set; }
        public FrmLoader()
        {
            InitializeComponent();
        }

        public FrmLoader(int width, int height)
        {
            InitializeComponent();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propertyName = "")
        {
            if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public void UpdateProgress(string detail, int percent)
        {
            Percentage = percent;
            Detail = detail;
        }

        private void FrmLoader_Load(object sender, EventArgs e)
        {
            var binding = new Binding("Value", this, "Percentage");
            cpbLoader.DataBindings.Add(binding);

            binding = new Binding("Text", this, "Percentage", true, DataSourceUpdateMode.OnPropertyChanged);
            binding.Format += (s, evt) =>
            {
                evt.Value = evt.Value.ToString();
            };
            cpbLoader.DataBindings.Add(binding);

            binding = new Binding("Text", this, "Detail");
            lblDetail.DataBindings.Add(binding);
        }
    }
}
